import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

import orderRouter from './order' // 订单管理
import operationRouter from './operation' // 运营中心
import settingRouter from './settings' //系统设置
import userRouter from './user' // 用户管理
import goodsRouter from './goods' // 商品管理
import IntegralRouter from './integral' // 积分管理

export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    name: 'Home',
    children: [
      {
        path: 'home',
        name: 'Home',
        meta: { title: '首页', icon: 'el-icon-house', noCache: true },
        component: () => import('@/views/home')
      }
    ]
  },
  {
    path: '/company-system',
    component: Layout,
    name: 'companySystem',
    children: [
      {
        path: '/company-system/staff',
        name: 'Staff',
        meta: { title: '从业人员', icon: 'el-icon-house', noCache: true },
        component: () => import('@/views/staff/index')
      }
    ]
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/410',
    component: () => import('@/views/error-page/410'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRoutes = [
  userRouter,
  goodsRouter,
  orderRouter,
  operationRouter,
  IntegralRouter,
  settingRouter
]

const createRouter = () =>
  new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
